package com.sxtyxt.online.me;

import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.sxtyxt.entity.ResultVo;
import com.sxtyxt.entity.User;
import com.sxtyxt.entity.UserInfo;
import com.sxtyxt.online.ActBase;
import com.sxtyxt.online.ActLogin;
import com.sxtyxt.online.ActMains;
import com.sxtyxt.online.App;
import com.sxtyxt.online.R;
import com.sxtyxt.online.SystemConst;
import com.sxtyxt.online.SystemEnv;
import com.sxtyxt.util.GsonUtil;
import com.sxtyxt.util.ProgressUtil;
import com.sxtyxt.volley.LoadingDialogResultListenerImpl;
import com.sxtyxt.volley.ResultListenerImpl;
import com.sxtyxt.volley.URL;
import com.sxtyxt.volley.VolleyUtils;

/**
 * 我的信息
 *
 * @author General
 */
public class ActMyInfo extends ActBase {
    private TextView txtUserName, txtUserJob, txtUserPhone, txtCompanyName, txtCommpanyLocation;
    private ActLogin actLogin;

    @Override
    protected int getLayoutId() {
        return R.layout.myinfo;
    }

    @Override
    protected void initUI() {
        super.initUI();
        actLogin=new ActLogin();
        txtUserName = (TextView) findViewById(R.id.txt_userName);
        txtUserJob = (TextView) findViewById(R.id.txt_userJob);
        txtUserPhone = (TextView) findViewById(R.id.txt_userPhone);
        txtCompanyName = (TextView) findViewById(R.id.txt_companyName);
        txtCommpanyLocation = (TextView) findViewById(R.id.txt_commpanyLocation);
        requestData();
        Log.e("88888888888888","执行了requestData()方法");
    }

    private void requestData() {
        ProgressUtil.show(this, "数据加载中，请稍候");
        Log.e("++++++++++++++++++",actLogin.getPkId()+"");
        VolleyUtils.requestService(SystemConst.MYINFO_URL,
                URL.getLoadingMyInfoParams(actLogin.getPkId()),
                new ResultListenerImpl(this) {
                    @Override
                    public void onSuccess(String response) {
                        super.onSuccess(response);
                        ActMyInfo.MyInfoVo  myInfoVo = GsonUtil.deser(response, ActMyInfo.MyInfoVo.class);
                        if (myInfoVo == null) {
                            ProgressUtil.hide();
                            doToast(R.string.msg_wso_error);
                            return;
                        }
                        if (myInfoVo.getResult() == 1) {
                            if (myInfoVo.getList() != null && myInfoVo.getList().size() > 0) {
                                UserInfo userInfo = myInfoVo.getList().get(0);
                                if (userInfo!=null) {
                                    txtUserName.setText("用户姓名："+userInfo.getUserName());
                                    txtUserJob.setText("用户职位："+userInfo.getUserJob());
                                    txtUserPhone.setText("用户电话："+userInfo.getUserPhone());
                                    txtCompanyName.setText("所属公司："+userInfo.getCompanyname());
                                    txtCommpanyLocation.setText("公司位置："+userInfo.getCompanyaddress());
                                }else {
                                    doToast("数据加载失败，请重试");
                                    ProgressUtil.hide();
                                }


                            } else {
                                doToast("数据加载失败，请重试");
//                                ProgressUtil.hide();
                            }
                        } else {
                            doToast(myInfoVo.getMsg());
                            ProgressUtil.hide();
                        }
                    }

                    @Override
                    public void onError() {
                        super.onError();
                        ProgressUtil.hide();
                    }

                });
    }
    class MyInfoVo extends ResultVo<UserInfo> {

        /**
         *
         */
        private static final long serialVersionUID = 1L;

    }


}
